﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc。@Copy Right 2019
// 文件： UserInfo.cs
// 项目名称：斑马车务
// 创建时间：2019-07-31
// 负责人：lsc
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using Dapper.Extensions;
using YouWei.Infrastructure.Entity;
using YouWei.Infrastructure.Repository;
using YouWei.Infrastructure.Models;

namespace YouWei.Infrastructure.Service
{

    /// <summary>
    ///用户表
    /// </summary>
    public class UserInfoService
    {
        protected UserInfoRepository repository;

        public UserInfoService()
        {
            repository = new UserInfoRepository();
        }

        #region 增删改查

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(UserInfo entity) { return repository.Insert(entity); }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(List<UserInfo> entitys) { return repository.Insert(entitys); }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Update(UserInfo entity) { return repository.Update(entity); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Delete(UserInfo entity) { return repository.Delete(entity); }

        /// <summary>
        /// 删除所有
        /// </summary>
        /// <returns></returns>
        public bool DeleteAll() { return repository.DeleteAll(); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public bool Delete(int primaryKey) { return repository.Delete(primaryKey); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public UserInfo SingleOrDefault(object primaryKey) { return repository.SingleOrDefault(primaryKey); }


        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public UserInfo Single(object primaryKey) { return repository.Single(primaryKey); }

        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<UserInfo> QueryAll()
        {
            return repository.QueryAll();
        }

        #endregion


        /// <summary>
        /// 查询用户列表
        /// 此方法仅用于管理员
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public Page<UserInfoPageModel> Pages(int pageIndex, int pageSize, UserSearchModel model)
        {
            return repository.Pages(pageIndex, pageSize, model);
        }


        /// <summary>
        /// 查询用户列表
        /// 获取特定用户的子用户
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageSize"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public Page<UserInfo> Pages(int pageIndex, int pageSize, int userId, UserSearchModel model)
        {
            return repository.Pages(pageIndex, pageSize, userId, model);
        }
        /// <summary>
        /// 查询公司下用户列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageSize"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public Page<UserInfo> PagesByCompanyID(int pageIndex, int pageSize, int companyId, UserSearchModel model)
        {
            return repository.PagesByCompanyID(pageIndex, pageSize, companyId, model);
        }
        /// <summary>
        /// 根据手机号获取用户信息
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public UserInfo GetUserInfoByMobile(string mobile)
        {
            return repository.GetUserInfoByMobile(mobile);
        }

        /// <summary>
        /// 根据OpenID获取用户信息
        /// </summary>
        /// <param name="OpenID"></param>
        /// <returns></returns>
        public UserInfo GetUserInfoByOpenID(string OpenID)
        {
            return repository.GetUserInfoByOpenID(OpenID);
        }


        /// <summary>
        /// 根据openid获取用户信息
        /// </summary>
        /// <param name="openId"></param>
        /// <returns></returns>
        public WxUserDto GetUserByOpenID(string openId)
        {
            return repository.GetUserByOpenID(openId);
        }
        /// <summary>
        /// 获取一个随机用户信息
        /// </summary>
        /// <returns></returns>
        public UserInfo GetUserInfoRandom() {
            return repository.GetUserInfoRandom();
        }

        /// <summary>
        /// 设置用户有效
        /// </summary>
        /// <param name="userId"></param>
        public void SetUserValid(int userId)
        {
            repository.SetUserValid(userId);
        }
    }

}